# coding=UTF-8
'''
封装驱动.
'''

from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy

S = "zhifubao"


class AppDriver:


    caps = {
        # "deviceName": "7XB4C18B23007643",# 我的荣耀8x
        "deviceName": ("%s" % S),  # 随便写就可以这个参数
        "platformName": "Android",
        "appPackage": "com.eg.android.AlipayGphone",
        "appActivity": "com.eg.android.AlipayGphone.AlipayLogin",
        # 设置超时时间
        "newCommandTimeout": 6000,
        # 不重置被测应用
        "noReset": True
    }

    driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', caps)

    driver.implicitly_wait(10)
    # globals()['loginname'] = gonggongfangfa.name_phone(cls)[0]
    # globals()["riqi"] = time.strftime('%m%d%H%M', time.localtime(time.time()))
    driver.find_element(AppiumBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("蚂蚁森林")').click()
    a = driver.find_element(AppiumBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("蚂蚁森林")').text
    b = driver.find_element(AppiumBy.XPATH, '(//android.widget.RelativeLayout[@resource-id="com.alipay.android.phone.openplatform:id/home_app_view"])[8]').text
    print(a,b)
    # myslIcon = (AppiumBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("蚂蚁森林")')

    def __int__(self, driver):
        self.driver = driver

#
# def Dr(self):
#     self.Dri()
#
#
# if __name__ == '__main__':
#     D = AppDriver()
#     Dr(D)